import config

def doModel(env, output):
	path = env['QUERY_STRING']
	id = path.split('id=')[1]
	import database
	db = database.db(config.hostdb, config.portdb, config.namedb, 
		config.userdb, config.passdb)
	row = db.getText(id)
	print row
	
	output.addBody("tpl_title_output", row[0])
	output.addBody("tpl_language", row[2])

	from pygments import highlight
	from pygments.lexers import get_lexer_by_name
	from pygments.formatters import HtmlFormatter
	
	
	lexer = get_lexer_by_name(row[2].lower(), stripall=False)
	formatter = HtmlFormatter(linenos=True, encoding="utf8")
	result = highlight(row[1], lexer, formatter)
	print type(result)
	output.addBody("tpl_text_output", result)
	output.addBody("tpl_highlight", HtmlFormatter().get_style_defs('.highlight'))
	
